<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      /*getType函数，用于获取变量的类型*/
      function getType(target) {
        let originType = Object.prototype.toString.call(target); // 获取内部属性值

        let index = originType.indexOf(" "); // 以空格分割

        let type = originType.slice(index + 1, -1); // 截取

        return type.toLowerCase();
      }
      console.log(getType(123)); // "number"
      console.log(getType("hello")); // "string"
      console.log(getType(true)); // "boolean"
      console.log(getType(null)); // "null"
      console.log(getType(undefined)); // "undefined"
      console.log(getType({})); // "object"
      console.log(getType([])); // "array"
      console.log(getType(new Date())); // "date"
      console.log(getType(/test/g)); // "regexp"
      console.log(getType(new Set())); // "set"
      console.log(getType(new Map())); // "map"
      console.log(getType(Symbol())); // "symbol"
      console.log(getType(BigInt(123))); // "bigint"
    </script>
  </body>
</html>
